﻿using System.Linq;
using BestEasyCMS.Model.IRepository.Security;
using BestEasyCMS.Model.Security;
using BestEasyCMS.Service.Interfaces.Security;
using BestEasyCMS.Service.Mappers;
using BestEasyCMS.Service.Messages;
using BestEasyCMS.Service.Views.Security;

namespace BestEasyCMS.Service.Impl.Security
{
    public class ResourceService:IResourceService
    {
        private readonly IResourceRepository _resourceRepository;

        public ResourceService(IResourceRepository resourceRepository)
        {
            _resourceRepository = resourceRepository;
        }

        public FindsResponse<ResourceView> GetAllResources()
        {
            var response = new FindsResponse<ResourceView>();
            var results = _resourceRepository.FindAll();
            var entitys = results as Resource[] ?? results.ToArray();
            if (!entitys.Any())
            {
                response.IsSuccess = false;
                response.Message = "无相关数据！";
                return response;
            }
            response.IsSuccess = true;
            response.Message = "获取成功！";
            response.Views = Convert<ResourceView, Resource>.ToViews(entitys);
            return response;
            
        }
    }
}
